{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "color-uzbekistan",
   "metadata": {},
   "source": [
    "# 第二课 微积分基本运算\n",
    "## 极限\n",
    "`Limit[f[x],x->x0]`=$\\lim_{x \\to x_0} f(x)$\n",
    "\n",
    "`Limit[f[x],x->x0,Direction->-1]`=$\\lim_{x \\to {x_0}^+} f(x)$\n",
    "> 从左逼近，右导数\n",
    "\n",
    "`Limit[f[x],x->x0,Direction->1]`=$\\lim_{x \\to {x_0}^-} f(x)$\n",
    "> 从右逼近，左导数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "loose-cambodia",
   "metadata": {},
   "outputs": [],
   "source": [
    "f[x_] := If[x<0,1-x,x^2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "marine-comfort",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "Indeterminate"
      ]
     },
     "execution_count": 7,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Limit[f[x],x->0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "simplified-audio",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "-Graphics-"
      ]
     },
     "execution_count": 8,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Plot[f[x],{x,-1,1}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "incorrect-clark",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><pre style=\"&#102;&#111;&#110;&#116;&#45;&#102;&#97;&#109;&#105;&#108;&#121;&#58;&#32;&#34;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#32;&#78;&#101;&#119;&#34;&#44;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#44;&#109;&#111;&#110;&#111;&#115;&#112;&#97;&#99;&#101;&#59;\">&#48;</pre></div>"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 9,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Limit[f[x],x->0,Direction->-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "upset-belgium",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><pre style=\"&#102;&#111;&#110;&#116;&#45;&#102;&#97;&#109;&#105;&#108;&#121;&#58;&#32;&#34;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#32;&#78;&#101;&#119;&#34;&#44;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#44;&#109;&#111;&#110;&#111;&#115;&#112;&#97;&#99;&#101;&#59;\">&#49;</pre></div>"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 10,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Limit[f[x],x->0,Direction->1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "present-confidence",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><pre style=\"&#102;&#111;&#110;&#116;&#45;&#102;&#97;&#109;&#105;&#108;&#121;&#58;&#32;&#34;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#32;&#78;&#101;&#119;&#34;&#44;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#44;&#109;&#111;&#110;&#111;&#115;&#112;&#97;&#99;&#101;&#59;\">&#49;</pre></div>"
      ],
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 13,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Limit[Sin[x]/x,x->0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "recovered-selling",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><pre style=\"&#102;&#111;&#110;&#116;&#45;&#102;&#97;&#109;&#105;&#108;&#121;&#58;&#32;&#34;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#32;&#78;&#101;&#119;&#34;&#44;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#44;&#109;&#111;&#110;&#111;&#115;&#112;&#97;&#99;&#101;&#59;\">&#48;</pre></div>"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 15,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Limit[(1-x)Tan(Pi x/2),x->1]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "specialized-controversy",
   "metadata": {},
   "source": [
    "## 微分\n",
    "### 函数的导数\n",
    "`D[f,x]`=$\\frac{\\partial f}{\\partial x}$\n",
    "\n",
    "`D[f,x,y]`=$\\frac{\\partial^2 f}{\\partial x \\partial y}$\n",
    "\n",
    "`D[f,{x,n}]`=$\\frac{\\partial^n f}{\\partial x^n}$\n",
    "\n",
    "`D[f,x,NonConstants->{a1,a2,...}]`\n",
    "> NonConstants:非常量 指明其变量是依赖于x的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "sorted-texas",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "x\n",
       "--\n",
       " x\n",
       "E"
      ]
     },
     "execution_count": 1,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v=x E^-x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "arbitrary-accountability",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "  -x   x   -2   x   5    x\n",
       "{E   - --, -- + --, -- - --}\n",
       "        x   x    x   x    x\n",
       "       E   E    E   E    E"
      ]
     },
     "execution_count": 22,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{D[v,x],D[v,{x,2}],D[v,{x,5}]}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "starting-humanity",
   "metadata": {},
   "source": [
    "### 全微分\n",
    "\n",
    "`Dt[f]`=$d f$\n",
    "\n",
    "`Dt[f,x]`=$\\frac{d f}{d x}$\n",
    "\n",
    "`Dt[f,x,y]`=`Dt[Dt[f,x],y]`=$\\frac{\\partial }{\\partial y}\\frac{\\partial f}{\\partial x}=\\frac{\\partial^2 f}{\\partial x \\partial y}$"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "labeled-crazy",
   "metadata": {},
   "source": [
    "## 计算积分\n",
    "### 不定积分\n",
    "`Integrate[f,x]`=$\\int f(x) d x$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "respective-edgar",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       " a x\n",
       "E    (-4 Cos[4 x] + a Sin[4 x])\n",
       "-------------------------------\n",
       "                  2\n",
       "            16 + a"
      ]
     },
     "execution_count": 23,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Integrate[Exp[a x]Sin[4x],x]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "cloudy-medium",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "-2 (Log[-1 + Sqrt[5] - 2 x] - Log[1 + Sqrt[5] + 2 x])\n",
       "-----------------------------------------------------\n",
       "                       Sqrt[5]"
      ]
     },
     "execution_count": 24,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Integrate[2/(1-x-x^2),x]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "international-title",
   "metadata": {},
   "source": [
    "### 定积分\n",
    "`Integrate[f,{x,a,b}]`=$\\int_a^b f(x) d x$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "offshore-console",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "1 + a - Cos[a]"
      ]
     },
     "execution_count": 25,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Integrate[1+Sin[x],{x,0,a}]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "permanent-louisiana",
   "metadata": {},
   "source": [
    "### 数值积分\n",
    "`NIntegrate[f,{x,a,b}]`=$\\int_a^b f(x) d x$\n",
    "\n",
    "`NIntegrate[f[x,y],{x,a,b},{y,c,d}]`=$\\int_a^b\\int_c^d f(x,y) d x d y$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "legendary-communist",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><pre style=\"&#102;&#111;&#110;&#116;&#45;&#102;&#97;&#109;&#105;&#108;&#121;&#58;&#32;&#34;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#32;&#78;&#101;&#119;&#34;&#44;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#44;&#109;&#111;&#110;&#111;&#115;&#112;&#97;&#99;&#101;&#59;\">&#50;&#46;&#54;&#50;&#56;&#53;&#51;</pre></div>"
      ],
      "text/plain": [
       "2.62853"
      ]
     },
     "execution_count": 26,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NIntegrate[(2+Sin[x])/(1+x),{x,2,10}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "saved-triangle",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><pre style=\"&#102;&#111;&#110;&#116;&#45;&#102;&#97;&#109;&#105;&#108;&#121;&#58;&#32;&#34;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#32;&#78;&#101;&#119;&#34;&#44;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#44;&#109;&#111;&#110;&#111;&#115;&#112;&#97;&#99;&#101;&#59;\">&#49;&#51;&#46;&#51;&#55;&#50;&#56;</pre></div>"
      ],
      "text/plain": [
       "13.3728"
      ]
     },
     "execution_count": 32,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NIntegrate[ArcTan[1+Sqrt[3 x]],{x,0,10}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "fleet-cigarette",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><img alt=\"Output\" src=\"\"></div>"
      ],
      "text/plain": [
       "-Graphics-"
      ]
     },
     "execution_count": 36,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RegionPlot[y<2 x && y > x^2,{x,0,2},{y,0,4}]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "different-boutique",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><pre style=\"&#102;&#111;&#110;&#116;&#45;&#102;&#97;&#109;&#105;&#108;&#121;&#58;&#32;&#34;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#32;&#78;&#101;&#119;&#34;&#44;&#67;&#111;&#117;&#114;&#105;&#101;&#114;&#44;&#109;&#111;&#110;&#111;&#115;&#112;&#97;&#99;&#101;&#59;\">&#48;&#46;&#50;&#57;&#52;&#52;&#52;&#49;</pre></div>"
      ],
      "text/plain": [
       "0.294441"
      ]
     },
     "execution_count": 38,
     "metadata": {
      "text/html": [],
      "text/plain": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NIntegrate[Boole[y<2 x && y > x^2]*Sin[x+y],{x,0,2},{y,0,4}]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Wolfram",
   "language": "Wolfram Language",
   "name": "wolframlanguage12.2"
  },
  "language_info": {
   "codemirror_mode": "mathematica",
   "file_extension": ".m",
   "mimetype": "application/vnd.wolfram.m",
   "name": "Wolfram Language",
   "pygments_lexer": "mathematica",
   "version": "12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
